package com.ruoyi.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.teaching.vo.DailyInterviewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.YaDailyTasks;
import com.ruoyi.teaching.service.IYaDailyTasksService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 每日任务Controller
 *
 * @author ruoyi
 * @date 2025-03-22
 */
@RestController
@RequestMapping("/daily_tasks")
public class YaDailyTasksController extends BaseController
{
    @Autowired
    private IYaDailyTasksService yaDailyTasksService;


    /**
     * 查询每日任务列表
     */
    @RequiresPermissions("teaching:daily_tasks:list")
    @GetMapping("/interview")
    public TableDataInfo interviewList(@RequestParam("date")String date, @RequestParam("classesId")Long classesId)
    {
        List<DailyInterviewVO> list = yaDailyTasksService.selectYaDailyTasksInterviewList(date,classesId);
        return getDataTable(list);
    }


    /**
     * 查询每日任务列表
     */
    @RequiresPermissions("teaching:daily_tasks:list")
    @GetMapping("/list")
    public TableDataInfo list(YaDailyTasks yaDailyTasks)
    {
        startPage();
        List<YaDailyTasks> list = yaDailyTasksService.selectYaDailyTasksList(yaDailyTasks);
        return getDataTable(list);
    }

    /**
     * 导出每日任务列表
     */
    @RequiresPermissions("teaching:daily_tasks:export")
    @Log(title = "每日任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YaDailyTasks yaDailyTasks)
    {
        List<YaDailyTasks> list = yaDailyTasksService.selectYaDailyTasksList(yaDailyTasks);
        ExcelUtil<YaDailyTasks> util = new ExcelUtil<YaDailyTasks>(YaDailyTasks.class);
        util.exportExcel(response, list, "每日任务数据");
    }

    /**
     * 获取每日任务详细信息
     */
    @RequiresPermissions("teaching:daily_tasks:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yaDailyTasksService.selectYaDailyTasksById(id));
    }

    /**
     * 新增每日任务
     */
    @Log(title = "每日任务", businessType = BusinessType.INSERT)
    @PostMapping("/quartz")
    @InnerAuth
    public R<Boolean> createDailyTask()
    {
        return R.ok(yaDailyTasksService.createDailyTask());
    }

    /**
     * 修改每日任务
     */
    @RequiresPermissions("teaching:daily_tasks:edit")
    @Log(title = "每日任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YaDailyTasks yaDailyTasks)
    {
        return toAjax(yaDailyTasksService.updateYaDailyTasks(yaDailyTasks));
    }

    /**
     * 删除每日任务
     */
    @RequiresPermissions("teaching:daily_tasks:remove")
    @Log(title = "每日任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yaDailyTasksService.deleteYaDailyTasksByIds(ids));
    }
}
